<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="林镭特">
    <title></title>
    <style>
        div{
            width: 150px;
            height: 150px;
            margin-left: 10px;
            margin-top: 50px;
            /* background-color: red; */
            display: inline-block;
        }
    </style>
</head>
<body>
    <!-- 循环将三个div变成红色 -->
    <button>点击将DIV变成红色</button>

    <div></div>
    <div></div>
    <div></div>

<script>
    var button=document.querySelector('button')
    var div=document.querySelectorAll('div')

    for(var i=0;i<3;i++){
        div[i].style.backgroundColor='black'
    }
    

    button.onclick=function () {
        for(var i=0;i<3;i++){
            div[i].style.backgroundColor='red'
        }
    }
</script>
</body>
</html>